package ltq.dataWash;


import java.io.*;

public class SmartphoneUse {
    public static void main(String[] args) {
        SmartphoneUse smartphoneUse=new SmartphoneUse();
        smartphoneUse.countFile("src/main/resources/ltqdata/electronicsWashed.csv");
    }

    public void smartphoneWash(){
        String dirRead = "src/main/resources/ltqdata/电子产品销售分析.csv";
        File fileRead = new File(dirRead);
        String dirWrite = "src/main/resources/ltqdata/electronicsWashed.csv";
        File fileWrite = new File(dirWrite);
        try {
            // 文件读
            BufferedReader br = new BufferedReader(new FileReader(fileRead));
            String line;
            // 文件写
            if (!fileWrite.exists())
                fileWrite.createNewFile();
            BufferedWriter bw = new BufferedWriter(new FileWriter(fileWrite));

            while ((line=br.readLine())!=null) {
                String[] partitions=line.split(",");
                if (partitions[5].equals("")||partitions[6].equals("")||partitions[7].equals("")||partitions[9].equals("")||partitions[10].equals("")||partitions[11].equals("")){
                    System.out.println(partitions[0]);
                }else {
                    bw.write(line+"\n");
                }

            }
            bw.flush();
            bw.close();
            br.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void countFile(String dir){
        int count=0;
//        dir = "src/main/resources/stormTestData";
        File file = new File(dir);
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;
            while ((line=br.readLine())!=null) {
                count++;
            }
            br.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println(count);
    }
}
